package com.snake.springboot.custom.controller.login;

import com.snake.springboot.custom.api.model.login.LoginModel;
import com.snake.springboot.custom.api.response.login.MainAccLoginRsp;
import com.snake.springboot.custom.api.service.login.MainAccLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.security.account.AccountData;
import org.snake.common.utils.IllegalStrUtils;
import org.snake.common.validate.Create;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>主账号登录
 * 类{@code MainAccLogin} </br>
 * 创建时间2025/2/13 10:37
 *
 * @author yangxt
 * @see
 */
@Api(tags = "商户管理-主账号登录")
@RestController
@RequestMapping("/login/main-acc")
public class MainAccLoginController {

    private MainAccLoginService mainAccLoginService;
    @Autowired
    public MainAccLoginController(MainAccLoginService mainAccLoginService) {
        this.mainAccLoginService = mainAccLoginService;
    }

    @ApiOperation("主账号登录")
    @PostMapping("/login")
    public ResponseResult<Object> login(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) LoginModel model) {
        MainAccLoginRsp rsp = mainAccLoginService.login(model);
        boolean b = IllegalStrUtils.pwdPattern(model.getPassword());
        String msg = "登录成功！！";
        if (!b){
            msg = "密码过于简单，有泄露风险，请及时修改！！";
        }
        return ResponseResultFactory.ucc(msg,rsp);
    }

    @ApiOperation("获取登录账号")
    @PostMapping("/get_account")
    public ResponseResult<AccountData> empAccount(
            @ApiParam(name = "对象", value = "传入json格式", required = true)
            @RequestBody AccountData model) {
        AccountData rspModel = mainAccLoginService.mainAccount(model);
        return ResponseResultFactory.ucc("获取账号信息成功！！",rspModel);
    }

}
